//
//  JCColorUtil.swift
//  JCPublicKit
//
//  Created by JasonLee on 2020/5/13.
//

import Foundation

class JCColorUtil: NSObject {
    @objc static func color(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat = 1) -> UIColor {
        UIColor(red: red / 255.0, green: green / 255.0, blue: blue / 255.0, alpha: alpha)
    }
    @objc static func color(hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat = 1) -> UIColor {
        UIColor(hue: hue / 256.0, saturation: saturation / 256.0, brightness: brightness / 256.0, alpha: alpha)
    }
    @objc static func color(hex: Int, alpha: CGFloat = 1) -> UIColor {
        let red     = CGFloat(((hex & 0xFF0000) >> 16))
        let green   = CGFloat(((hex & 0xFF00) >> 8))
        let blue    = CGFloat((hex & 0xFF))
        return color(red: red, green: green, blue: blue, alpha: alpha)
    }
    @objc static func random() -> UIColor {
        let red: CGFloat = CGFloat(arc4random_uniform(255) + 0) / 255.0
        let green: CGFloat = CGFloat(arc4random_uniform(255) + 0) / 255.0
        let blue: CGFloat = CGFloat(arc4random_uniform(255) + 0) / 255.0
        return UIColor(red: red, green: green, blue: blue, alpha: 1)
    }
}

extension UIColor {
    @objc static func jc_color(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat = 1) -> UIColor {
        JCColorUtil.color(red: red, green: green, blue: blue, alpha: alpha)
    }
    @objc static func jc_color(hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat = 1) -> UIColor {
        JCColorUtil.color(hue: hue, saturation: saturation, brightness: brightness, alpha: alpha)
    }
    @objc static func jc_color(hex: Int, alpha: CGFloat = 1) -> UIColor {
        JCColorUtil.color(hex: hex, alpha: alpha)
    }
    @objc static var jc_random: UIColor {
        JCColorUtil.random()
    }
}
